<template>
    <div class="comment-reply">
        <van-nav-bar :title="comment.reply_count > 0 ? `${comment.reply_count}条回复` : '暂无回复'">
            <van-icon slot="left" name="cross" @click="$emit('close')"></van-icon>
        </van-nav-bar>

        <div class="scroll-wrap">
            <!-- 当前评论项 -->
            <CommentItem :comment="comment"/>

            <!-- 回复列表 -->
            <van-cell title="全部回复"/>
            <CommentList type="c" :source="comment.com_id" :list="commentList"/>
        </div>

        <div class="post-wrap">
            <van-button class="post-btn" size="small" round @click="isPostShow = true">回复评论</van-button>
        </div>
        <van-popup v-model="isPostShow" round position="bottom" :style="{ height: '80%' }" >
            <CommentPost :target="comment.com_id" @postSuccess="onPostSuccess"/>
        </van-popup>
    </div>
</template>

<script>
import CommentItem from './comment-item.vue'
import CommentList from './comment-list.vue'
import CommentPost from './comment-post.vue'

export default {
    name: 'CommentReply',
    props: ['comment'],
    components: {
        CommentItem,
        CommentList,
        CommentPost
    },
    data () {
        return {
            isPostShow: false,
            commentList: []
        }
    },
    methods: {
        onPostSuccess (data) {
            this.comment.reply_count++
            this.isPostShow = false
            this.commentList.unshift(data.new_obj)
        }
    }
}
</script>

<style scoped lang="less">
/deep/ .van-nav-bar__title {
    color: #000;
}

.scroll-wrap {
    position: fixed;
    top: 262px;
    left: 0;
    right: 0;
    bottom: 88px;
    overflow-y: auto;
}
.post-wrap {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 88px;
    background-color: #3296fa;
    .post-btn {
        width: 60%;
    }
}
</style>
